MySQL

class MySQL(url: String, username: String, password: String, options: ConnectionPool.Options = ConnectionPool.Options(), val encoders: ValueEncoderRegistry = ValueEncoderRegistry()) : IMySQL(source)

The MySQL class provides a driver implementation for interacting with a MySQL database. It supports connection pooling, transactional operations, and executing SQL queries.

The connection URL should follow the nex pattern, as described by MySQL.

The generic format of the connection URL: mysql://:port?properties

The port defaults to 3306. The properties are the ones the native driver (sqlx) reads: ssl-mode (disabled, preferred, required, verify_ca, verify_identity), ssl-ca, ssl-cert, ssl-key, socket and timezone (the session time zone, UTC by default), as well as r2dbc's ssl=true|false. charset, collation and statement-cache-capacity are accepted and have no effect on the JVM. Any other property is rejected.

Parameters

url

The connection URL for the MySQL database.

username

The username for authenticating with the database.

password

The password for authenticating with the database.

options

The optional configuration for the connection pool, such as min/max connections and timeout settings.

encoders

Optional registry of value encoders to use for encoding query parameters.

Constructors

Link copied to clipboard
constructor(url: String, username: String, password: String, options: ConnectionPool.Options = ConnectionPool.Options(), encoders: ValueEncoderRegistry = ValueEncoderRegistry())

Types

Link copied to clipboard
object Companion
Link copied to clipboard
class R2dbcConnection(connection: Connection, val encoders: ValueEncoderRegistry) : Connection
Link copied to clipboard
class R2dbcTransaction(connection: Connection, closeConnectionAfterTx: Boolean, val encoders: ValueEncoderRegistry, savepoint: String? = null, parent: MySQL.R2dbcTransaction? = null) : Transaction

Properties

Link copied to clipboard
open override val encoders: ValueEncoderRegistry

Functions

Link copied to clipboard
open suspend override fun acquire(): Result<Connection>
Link copied to clipboard
open suspend override fun begin(): Result<Transaction>
Link copied to clipboard
open suspend override fun close(): Result<Unit>
Link copied to clipboard
open suspend override fun execute(statement: Statement): Result<Long>
open suspend override fun execute(sql: String): Result<Long>
Link copied to clipboard
open suspend override fun executeWithResult(statement: Statement): Result<ExecuteResult>
open suspend override fun executeWithResult(sql: String): Result<ExecuteResult>
Link copied to clipboard
open fun <T> fetch(statement: Statement, rowMapper: RowMapper<T>, fetchSize: Int): Flow<T>
open fun <T> fetch(sql: String, rowMapper: RowMapper<T>, fetchSize: Int): Flow<T>
open override fun fetch(statement: Statement, fetchSize: Int): Flow<ResultSet.Row>
open override fun fetch(sql: String, fetchSize: Int): Flow<ResultSet.Row>
Link copied to clipboard
open suspend fun <T> fetchAll(statement: Statement, rowMapper: RowMapper<T>): Result<List<T>>
open suspend fun <T> fetchAll(sql: String, rowMapper: RowMapper<T>): Result<List<T>>
open suspend override fun fetchAll(statement: Statement): Result<ResultSet>
open suspend override fun fetchAll(sql: String): Result<ResultSet>
Link copied to clipboard
open suspend override fun migrate(supplier: () -> List<MigrationFile>, table: String, schema: String?, createSchema: Boolean, afterStatementExecution: suspend (Statement, Duration) -> Unit, afterFileMigration: suspend (Migration, Duration) -> Unit): Result<Migrator.Results>
open suspend override fun migrate(path: String, table: String, schema: String?, createSchema: Boolean, afterStatementExecution: suspend (Statement, Duration) -> Unit, afterFileMigration: suspend (Migration, Duration) -> Unit): Result<Migrator.Results>
open suspend override fun migrate(files: List<MigrationFile>, table: String, schema: String?, createSchema: Boolean, afterStatementExecution: suspend (Statement, Duration) -> Unit, afterFileMigration: suspend (Migration, Duration) -> Unit): Result<Migrator.Results>
Link copied to clipboard
open override fun poolIdleSize(): Int
Link copied to clipboard
open override fun poolSize(): Int
Link copied to clipboard
open suspend fun <T> transaction(f: suspend Transaction.() -> T): T
Link copied to clipboard
open suspend fun <T> transactionCatching(f: suspend Transaction.() -> T): Result<T>
Link copied to clipboard
suspend fun <T> QueryExecutor.withReadBackTransaction(block: suspend (QueryExecutor) -> Result<T>): Result<T>

Runs block, a write and the read back of the row it wrote, in a single transaction: this executor itself when it is one, else one begun on it (on a connection of its own, when a pool), committed when block succeeds and rolled back when it fails.

Link copied to clipboard
suspend fun <T> QueryExecutor.withSingleConnection(block: suspend (QueryExecutor) -> Result<T>): Result<T>

Runs block on a single database connection: this executor itself when it already is one (a connection or a transaction), or a connection borrowed from it for the duration of block when it is a pool.